/*
 *	include/cos/ipc.h
 *
 *	created at 2007.10.01 by ChenJie
 *
 *	last modified at 2007.10.01
 *	
 */
#ifndef IPC_H
#define IPC_H

#define NR_MSG_CONTEXT		(6)
#define NR_NOTIFY_CONTEXT	(32)

// define message types:
#define HARDWARE_INT		(1)
#define SOFTWARE_INT		(2)
#define CLOCK_NOTIFICATION 	(3)
#define SYSTEM_NOTIFICATION	(4)
#define SEND			(5)
#define SENDREC			(6)

// define notifier:
#define NOTIFIER_BIT(PID)		(PID + 4)	// for notifying the software int
#define NOTIFIER_PID(BIT)		(BIT - 4)

struct msg_struct {
	 	 long		source;		// pid of the msg  come from
	unsigned long		type;		// what kinds of msg
	unsigned long		time;		// ...
	unsigned long		context[NR_MSG_CONTEXT];	// message body
};

struct msgbox_struct {
	struct msg_struct	sendbox;
	struct msg_struct	receivebox;
	unsigned long	notify_pending;
	unsigned long	notify_context[NR_NOTIFY_CONTEXT];
};

extern void msgbox_init(struct msgbox_struct *p);
extern long sys_send(long dst_pid, struct msg_struct * user_msg_ptr, unsigned long msgtype);
extern long sys_receive(long src_pid, struct msg_struct *user_msg_ptr);
extern long sys_notify(long src_pid, long dst_pid);
extern long sys_sendrec(long dst_pid, struct msg_struct *user_msg_ptr);

#endif
